(function($) {
	$(window).load(function(e) {
		
		$('[name="tahun"]').val($('#tahun').val());
				
		$("table#da-ex-datatable-numberpaging").dataTable({
			"aaSorting": [[ 0, "asc" ]],
			"aoColumns": [
				null,
				{ "bVisible":    false },
				null,
				null
			],
			"oLanguage": {
                "sUrl": "plugins/datatables/dataTables.indonesian.txt"
            },
			sPaginationType: "full_numbers"	
		});
		
			
		var oTable = $('#da-ex-datatable-numberpaging').dataTable( );
		var arr = oTable.fnGetData();
		
		var pb = new Array();
		for(var i=0;i<arr.length;i++){
			pb [i]=arr[i][3]; 
		}
		var bulan = new Array();
		for(var i=0;i<arr.length;i++){
			bulan [i]=arr[i][1]; 
		} 
		if( $.plot ) { 
			var 
				perkara = [],
				previousPoint = null;
			var startDate;
			var endDate;
			var tahun=new Date().getFullYear();
			
			if($('#tahun').val()!="-"){
				tahun = $('#tahun').val();
			}
			for(var i = 0; i < pb.length; i++) {
				
				perkara.push([new Date(Date.UTC(tahun, bulan[i]-1, 0)), pb[i]]);
				
				if(i==0){
					startDate = new Date(Date.UTC(tahun, bulan[i]-1, 0));
				}
				
				if(i==pb.length-1){
					endDate = new Date(Date.UTC(tahun, bulan[i], 0));
				}
				
			}
			
			var opts = {
				series: {
					lines: { show: true }, 
					points: { show: true }
				}, 
				tooltip: true, 
				tooltipOpts: {
					content: "jumlah perkara",
					defaultTheme: false
				}, 
				xaxis: {
					mode: "time", 
						min: startDate.getTime(),
						max: endDate.getTime()
				}, 
				grid: { 
					hoverable: true, 
					clickable: true, 
					borderWidth: null
				}
			};
			
			var plot = $.plot($("#da-ex-flot"), 
				[
				 { data: perkara, label: "Jumlah Perkara", color: "#fab241"}
				], 
				opts
			);
		}
		

	});
}) (jQuery);
